package org.example.springboot.common.service.impl;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.Wrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.example.springboot.common.query.Query;
import org.example.springboot.common.service.BaseService;


/**
 * 基础服务类，所有Service都要继承
 *
 *  @author Fz
 */
public class BaseServiceImpl<M extends BaseMapper<T>, T> extends ServiceImpl<M, T> implements BaseService<T> {

    /**
     * 获取分页对象
     *
     * @param query 分页参数
     */
    protected IPage<T> getPage(Query query) {
        return new Page<>(query.getPage(), query.getLimit());
    }

    public IPage<T> page(Query query, Wrapper<T> queryWrapper) {
        return this.baseMapper.selectPage(getPage(query), queryWrapper);
    }

}